<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<script>	
	var entryTable;
	var scripts = [null, null];
	$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
		entryTable= $("#entryInfoLists").dataTable({
			"bSort" : false,
			"oLanguage" : oLanguage,
			"destory":true,
			"sPaginationType": "full_numbers",
			"fnInitComplete": function(param){
				$("#entryInfoLists_filter").append("<button class=\"btn btn-sm btn-purple btn-right\" type=\"button\" id=\"btnAdd\">"+
						"<i class=\"ace-icon fa fa-plus-square bigger-110\"></i>"+
							"新增"+
						"</button>");
			},
			"aoColumnDefs": [
           
               /*  { "bSearchable": false, "bVisible": false, "aTargets": [6] } */
            ]
		});
		
		
		

		$("#btnAdd").on("click",function(){
			
			var param = {"dictType":$("#dictId").val()};
	  		$("#addEntryInfo").show();
	  		$("#addEntryInfo").load("${ctx}/dict/addEntry",param,function(){
	  			$("#addEntryInfo").data("entryBtnFlag","add").dialog("open");
	  		});
	  		
		});
		
		
		var active_class = 'success';
		$('#entryInfoLists').on('dblclick', 'tbody tr' , function(){
			
			var $row = $(this).closest('tr');	
			if ($row.hasClass(active_class) == false) {
				entryTable.$('tr.' + active_class).removeClass(active_class);
				$row.addClass(active_class);				
			}
		});
	});


	$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
		_title: function(title) {
			var $title = this.options.title || '&nbsp;'
			if( ("title_html" in this.options) && this.options.title_html == true )
				title.html($title);
			else title.text($title);
		}
	}));  
	
	//字典类型新增
	$('#addEntryInfo').dialog({
		hide:false,
		autoOpen:false,
		width: 710,
		height:450,
		modal:true,
		//bgiframe:true,
		title: "<div class='widget-header'><h4 class='smaller'><i class='ace-icon fa fa-cog green'></i>&nbsp; 编辑字典类型</h4></div>",
		title_html: true,
		open:function(event){
			var entryBtnFlag =$(this).data("entryBtnFlag");
            //alert("dictBtnFlag:"+entryBtnFlag);
			if(entryBtnFlag=="add"){
				$("#btnModify").hide();
				$("#btnDelete").hide();
				$("#btnSave").show();
				$("#btnCancle").hide();
			}else if(entryBtnFlag=="show"){
				$("#btnModify").show();
		    	$("#btnDelete").show();
		    	$("#btnSave").hide();
		    	$("#btnCancle").hide();
			}
		},
		buttons: [
		            
					{
						id: "btnModify",
						html: "<i class='ace-icon fa fa-pencil-square-o bigger-110'></i>&nbsp; 修改",
						"class" : "btn btn-primary btn-minier",
						click: function() {
							modify();
						}
					},
					{
						id: "btnSave",
						html: "<i class='ace-icon fa fa-floppy-o bigger-110'></i>&nbsp; 保存",
						"class" : "btn btn-success btn-minier",
						click: function() {
							save();
						}
					},
					{
						id: "btnCancle",
						html: "<i class='ace-icon fa fa-undo bigger-110'></i>&nbsp; 取消",
						"class" : "btn btn-warning btn-minier",
						click: function() {
							cancle();
						}
					},												
					{
						id: "btnClose",
						html: "<i class='ace-icon fa fa-times bigger-110'></i>&nbsp; 关闭",
						"class" : "btn btn-minier",
						click: function() {
							$(this).dialog("close");
						}
					}				
				]
			});
	
	
	
	function modifyEntry(dictType,dictCode){
		var params = {"dictType":dictType,"dictCode":dictCode};
	    $("#addEntryInfo").show(); 
		$("#addEntryInfo").load("${ctx}/dict/entryDetail.do", params,function(){
			$("#addEntryInfo").data("entryBtnFlag","show").dialog("open");
		});
		
	}
	
	function removeEntry(dictType,dictCode){
		var params = {
				"dictType":dictType,
				"dictCode":dictCode
			};
		var param ={"dictType":dictType};
		
		if(confirm("是否确定删除!")){
			$.ajax({
				async : false,
				url : "${ctx}/dict/deleteEntry.do",
				type : "post",
				data : $.param(params),
				dataType : "json",
				success : function(data){
					if(data[0]=="ok"){
						alert(data[1]);
						$("#addEntryInfo").hide();
						$("#addEntryInfo").dialog("close");
					   	$("#entryDetailInfo").show();
					   	$("#entryDetailInfo").load("${ctx}/dict/entryList.do",param);
						
					}else{
						alert(data[1]);
					}
				}
				});
		}
		
	}
	
</script>
<br>

<div class="row">
  <div class="col-xs-12">
    <div class="table-header">
					字典小类列表
	</div>
	<form id="entryInfoList">		
	 <input type="hidden" id="dictId" name="dictId" value="${dictType}" />	
		<table id="entryInfoLists"   class="table table-striped table-bordered table-hover">
	    <thead>
		<tr>
		    <th align="center" style="text-align:center;"><b>字典编码</b></th>
				
			<th align="center" style="text-align:center;"><b>字典码</b></th>
			
			<th align="center" style="text-align:center;"><b>字典值</b></th>
			<th align="center" style="text-align:center;"><b>备注</b></th>
			<th align="center" style="text-align:center;"><b>操作</b></th>
			
		</tr>
		</thead>
		<tbody>
		
		<c:forEach items="${entryList}" var="entry">
		   <tr>
		   <td>${entry.dictType}</td>
		
		   <td>${entry.dictCode}</td>
		
		   <td>${entry.dictValue}</td>
		   <td>${entry.remarks}</td>
		   <td>
		   		<div class="hidden-sm hidden-xs action-buttons">
					<a class="blue" href="javascript:void(0)" onclick="modifyEntry('${entry.dictType}','${entry.dictCode}')" title="修改">
						<i class="ace-icon fa fa-search-plus bigger-130"></i>
					</a>
					<a class="red" href="javascript:void(0)" onclick="removeEntry('${entry.dictType}','${entry.dictCode}')" title="删除">
						<i class="ace-icon fa fa-trash-o bigger-130"></i>
					</a>
				</div>
		   </td>
		   </tr>	
		   </c:forEach>
		</tbody>			
	</table>
	</form>
	</div>
</div>
<div id ="entryDetailInfo"></div>